number = int(input())

if len(str(number)) != 4 or number <= 0:
    print(0)
else:
    largest_prime = 0
    for i in range(4):
        for j in range(i + 1, 5):
            num = int(str(number)[i:j])

            is_prime = True
            if num <= 1:
                is_prime = False
            else:
                for k in range(2, int(num ** 0.5) + 1):
                    if num % k == 0:
                        is_prime = False
                        break

            if is_prime and num > largest_prime:
                largest_prime = num
    print(largest_prime)